var banner =document.querySelector('.banner')
var uls=banner.querySelectorAll('.banner ul li')
var ols =banner.querySelectorAll('.banner ol li');
var leftBtn=banner.querySelector('.banner .leftBtn');
var rightBtn=banner.querySelector('.banner .rightBtn');
var index =0;
    rightBtn.onclick=function(){
        index++;
        if(index===uls.length){
            index=0
        }
        for(var j=0; j<uls.length;j++){
            uls[j].className=''
            ols[j].className=''
        }
        uls[index].className='active';
        ols[index].className='active';
    }
    leftBtn.onclick=function(){
        index--;
        if(index<0){
            index=uls.length-1
        }
        for(var j=0; j<uls.length;j++){
            uls[j].className=''
            ols[j].className=''
        }
        uls[index].className='active';
        ols[index].className='active';
    }
    for(let i=0;i<ols.length;i++){
        ols[i].onmousemove=function(){
            for(var j=0; j<ols.length ; j++){
                uls[j].className=''
                ols[j].className=''
            }
            uls[i].className='active'
            ols[i].className='active'
        }
        
    }
    var timer=setInterval(function(){
        index++
        if(index===uls.length){
            index=0
        }
        for(i=0;i<uls.length;i++){
            uls[i].className=''
            ols[i].className=''
        }
        uls[index].className='active'
        ols[index].className='active'
    },3000)
    banner.onmouseover=function(){
        clearInterval(timer);
    }
    banner.onmouseout=function(){
        timer=setInterval(function(){
        index++
        if(index===uls.length){
            index=0
        }
        for(i=0;i<uls.length;i++){
            uls[i].className=''
            ols[i].className=''
        }
        uls[index].className='active'
        ols[index].className='active'
    },3000)
    }


   
var int=0
    var carousel = document.querySelector('.banner2')
    var uli = carousel.querySelectorAll('ul li')
    var oli = carousel.querySelectorAll('ol li')
    for(let j=0;j<oli.length;j++){
        oli[j].onmousemove=function(){
            int=j;
            for(var i=0;i<uli.length;i++){
                uli[i].className=''
                oli[i].className=''
            }
            uli[int].className='active'
            oli[int].className='active'
        }
    }
    var timid=setInterval(function(){
        int++
        if(int===uli.length){
            int=0
        }

        for(i=0;i<uli.length;i++){
            uli[i].className=''
            oli[i].className=''
        }
        uli[int].className='active'
        oli[int].className='active'
    },3000)
    
    carousel.onmouseover=function(){
        clearInterval(timid)
    }
    
    carousel.onmouseout=function(){
        timid=setInterval(function(){
        int++
        if(int===uli.length){
            int=0
        }
        for(i=0;i<uli.length;i++){
            uli[i].className=''
            oli[i].className=''
        }
        uli[int].className='active'
        oli[int].className='active'
    },3000)
    }

var username=getCookie("username")
var into1=document.querySelector('.into1  a')
var into=document.querySelector('.into1 ')
var into2=document.querySelector('.into2  a')
console.log(username)
if(username){
    console.log(into1)
    into.style.marginLeft='165px'
    into2.innerHTML=` <a href="javascript:;" class="logout">退出</a>`
    into1.innerHTML=`<a href="javascript:;" style="color:red;">${username}</a>`
    into2.querySelector('a.logout').onclick = function(){
        if(!confirm('你确定要离开吗？')){
            return false
        }
        removeCookie('username')
        into.style.marginLeft='219px'
        into1.innerHTML=`<a href="login.html">登录</a>`
        into2.innerHTML = `<a href="register.html">注册</a>`
    }
}